﻿using System;
using System.Text;
using System.Collections.Generic;
using System.Linq;
using Microsoft.VisualStudio.TestTools.UnitTesting;

namespace FCS.Test
{
    /// <summary>
    /// Summary description for FilterTest
    /// </summary>
    [TestClass]
    public class FilterTests : Functional
    {
        public FilterTests()
        {
            //
            // TODO: Add constructor logic here
            //
        }

        private TestContext testContextInstance;

        /// <summary>
        ///Gets or sets the test context which provides
        ///information about and functionality for the current test run.
        ///</summary>
        public TestContext TestContext
        {
            get
            {
                return testContextInstance;
            }
            set
            {
                testContextInstance = value;
            }
        }

        [TestMethod]
        public void SimpleFilterTest()
        {
            Assert.IsTrue(Equals(ListFromArray(2, 4, 6, 8, 10), Filter(v => v % 2 == 0, IntList(1, 10))));
            Assert.AreEqual(5, Length(Filter(v => v % 2 == 0, IntList(1, 10))));
            
            int n = 2;
            Assert.IsTrue(Equals(ListFromArray(2, 4, 6, 8, 10), Filter(v => v % n == 0, IntList(1, 10))));
            Assert.AreEqual(5, Length(Filter(v => v % n == 0, IntList(1, 10))));
        }

        [TestMethod]
        public void ParamFilterTest()
        {
            Assert.IsTrue(Equals(ListFromArray(2, 4, 6, 8, 10), Filter2((v, n) => v % n == 0, HeadValue(IntList(2,3)), IntList(1, 10))));
            Assert.AreEqual(5, Length(Filter2<int>((v, n) => v % n == 0, 2, IntList(1, 10))));
        }

        [TestMethod]
        public void ParamFilter2Test()
        {
            Assert.IsTrue(Equals(IntList(1, 10), Filter2((v, idx, n) => (v + idx - 1) % n == 0, HeadValue(IntList(2, 3)), IntList(1, 10))));
            Assert.AreEqual(10, Length(Filter2<int>((v, idx, n) => (v + idx - 1) % n == 0, 2, IntList(1, 10))));
        }
    }
}
